package com.dude.utils;

import java.io.InputStream;

import com.dude.R;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class OnFirstRun {
	
	private Activity activity;
	
	public OnFirstRun(Activity a)
	{
		this.activity = a;
	}
	
	// add new pre - installed objects with their pictures
	public boolean initialize()
	{
		FilesOperations fo = new FilesOperations(activity);
		if (!fo.initializeDirectory())
			return false;
		// create the wanted objects
		int i;
		i = fo.addObject("20 NIS Bill", true);
		if (i!=1)
			return false;
		i = fo.addObject("50 NIS Bill", true);
		if (i!=1)
			return false;
		i = fo.addObject("100 NIS Bill", true);
		if (i!=1)
			return false;
		i = fo.addObject("200 NIS Bill", true);
		if (i!=1)
			return false;
		i = fo.addObject("NIS Bills", false);
		if (i!=1)
			return false;		
		System.gc();
		
		// add pictures from resources 
		String name = null;
		InputStream is = activity.getResources().openRawResource(R.raw.bill20_1);		
		Bitmap image = BitmapFactory.decodeStream(is);  	
		name = fo.addImage("20 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();

		is = activity.getResources().openRawResource(R.raw.bill20_1b);		
		image = BitmapFactory.decodeStream(is);  
		name = fo.addImage("20 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();
				
		is = activity.getResources().openRawResource(R.raw.bill50_1);		
		image = BitmapFactory.decodeStream(is);  
		name = fo.addImage("50 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();	
		
		is = activity.getResources().openRawResource(R.raw.bill50_1b);		
		image = BitmapFactory.decodeStream(is);  
		name = fo.addImage("50 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();
				
		is = activity.getResources().openRawResource(R.raw.bill100_1);		
		image = BitmapFactory.decodeStream(is);  
		name = fo.addImage("100 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();		
		
		is = activity.getResources().openRawResource(R.raw.bill100_1b);		
		image = BitmapFactory.decodeStream(is);  	
		name = fo.addImage("100 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();		
		
		is = activity.getResources().openRawResource(R.raw.bill200_1);		
		image = BitmapFactory.decodeStream(is);  
		name = fo.addImage("200 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();
				
		is = activity.getResources().openRawResource(R.raw.bill200_1b);		
		image = BitmapFactory.decodeStream(is);  	
		name = fo.addImage("200 NIS Bill", image);
		if (name==null)
			return false;
		image.recycle();
		image = null;
		System.gc();
						
		// add the single objects to the multi object
		if (!fo.addObjectToMultiObject("NIS Bills", "20 NIS Bill"))
			return false;
		if (!fo.addObjectToMultiObject("NIS Bills", "50 NIS Bill"))
			return false;
		if (!fo.addObjectToMultiObject("NIS Bills", "100 NIS Bill"))
			return false;
		if (!fo.addObjectToMultiObject("NIS Bills", "200 NIS Bill"))
			return false;

		return true;
	}
	

}
